#

| Chapter 46 Shell Script Debugging and Gotchas |

## 46.3 Bourne Shell Debugger Shows a Shell Variable

If you have a shell script that sets several variables and you want to show the value of one of them, you can add a loop that asks you forvariable names and displays their values : (45.19)

>     % cat myscript
>     #!/bin/sh
>        ...
>     while echo "Pick a variable; just RETURN quits: \c"
>           read var
>     do
>           case "$var" in
>           "") break ;;
>           *)  eval echo \$$var ;;
>           esac
>     done

The loop prompts `Pick a variable:`, then reads a value; if you type an empty answer, the loop quits. Otherwise, the value of that variable is displayed; the eval (8.10) command scans the echo command line twice.

This tip isn't just good for debugging. It's good in any shell script where you need to show the value of a variable by typing its name.

- JP

46.2 Quoting Trouble? Think, Then Use echo |  | 46.4 Stop Syntax Errors in Numeric Tests